FROM centos:7

MAINTAINER kanyuxia

ENV FASTDFS_TMP_PATH=/usr/local/src \
    FASTDFS_PATH=/fdfs

# get all the package and directory
RUN yum install -y git gcc make wget vim \
    && yum -y install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel \
    && mkdir -p ${FASTDFS_PATH} \
    && mkdir -p ${FASTDFS_TMP_PATH}/libfastcommon \
    && mkdir -p ${FASTDFS_TMP_PATH}/fastdfs \
    && mkdir -p ${FASTDFS_TMP_PATH}/fastdfs-nginx-module \
    && git clone https://github.com/happyfish100/libfastcommon.git ${FASTDFS_TMP_PATH}/libfastcommon \
    && git clone https://github.com/happyfish100/fastdfs.git ${FASTDFS_TMP_PATH}/fastdfs \
    && git clone https://github.com/happyfish100/fastdfs-nginx-module.git ${FASTDFS_TMP_PATH}/fastdfs-nginx-module \
    && wget -P ${FASTDFS_TMP_PATH}/ https://nginx.org/download/nginx-1.12.1.tar.gz

# compile the libfastcommon and fastdfs
RUN cd ${FASTDFS_TMP_PATH}/libfastcommon \
    && ./make.sh \
    && ./make.sh install \
    && cd ${FASTDFS_TMP_PATH}/fastdfs \
    && ./make.sh \
    && ./make.sh install \
    && rm -rf ${FASTDFS_TMP_PATH}/libfastcommon \
    && rm -rf ${FASTDFS_TMP_PATH}/fastdfs

# compile fastdfs-nginx-module and nginx
RUN tar -zxvf /usr/local/src/nginx-1.12.1.tar.gz -C /usr/local/src/ \
    && cd /usr/local/src/nginx-1.12.1 \
    && ./configure --prefix=/opt/nginx/ --add-module=/usr/local/src/fastdfs-nginx-module/src/ \
    && make \
    && make install \
    && rm -f ${FASTDFS_TMP_PATH}/nginx-1.12.1.tar.gz \
    && rm -rf ${FASTDFS_TMP_PATH}/nginx-1.12.1 \
    && rm -rf ${FASTDFS_TMP_PATH}/fastdfs-nginx-module

VOLUME ["$FASTDFS_PATH"]

COPY conf/*.* /etc/fdfs/

COPY start.sh /usr/local/src/

# start
RUN chmod 777 /usr/local/src/start.sh

ENTRYPOINT ["/usr/local/src/start.sh"]

CMD ["tracker"]
